package com.macro.mall.common.log.config;

import com.macro.mall.common.log.UnifiedLogUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import javax.annotation.PostConstruct;

/**
 * 统一日志自动配置类
 * 在Spring Boot启动时自动配置统一日志工具
 * @author tiger
 */
@Configuration
@ConditionalOnClass(UnifiedLogUtil.class)
public class UnifiedLogAutoConfiguration {
    
    private final Environment environment;
    
    @Value("${spring.application.name:unknown}")
    private String serviceName;
    
    public UnifiedLogAutoConfiguration(Environment environment) {
        this.environment = environment;
    }
    
    @PostConstruct
    public void init() {
        // 初始化统一日志工具
        UnifiedLogUtil.setEnvironment(environment, serviceName);
    }
}